package com.jpl.demo.mobility.ui;


import com.jpl.demo.mobility.ui.view.BrowserMainView;
import com.jpl.demo.mobility.ui.view.SmartPhoneMainView;
import com.vaadin.addon.touchkit.ui.TouchKitApplication;
import com.vaadin.addon.touchkit.ui.TouchKitWindow;
import com.vaadin.terminal.gwt.server.WebBrowser;

public class BusTimingMobileApplication extends TouchKitApplication {

	private static final long serialVersionUID = 1L;

	private static final String DEFAULT_THEME = "mobile";

	@Override
	public void init() {
		setMainWindow(new TouchKitWindow());

		// Using mobile mail theme
		setTheme(DEFAULT_THEME);
	}

	@Override
	public void onBrowserDetailsReady() {
		WebBrowser browser = getBrowser();
		if (!browser.isTouchDevice()) {
			getMainWindow().showNotification(
					"You appear to be running on a desktop software or other non touch device. We'll show you the tablet (or smartphone view if small screen size) for debug purposess.");
		}

		if (isSmallScreenDevice()) {
			getMainWindow().setContent(new SmartPhoneMainView());
		} else {
			getMainWindow().setContent(new BrowserMainView());
		}
	}

	public boolean isSmallScreenDevice() {
		float viewPortWidth = getMainWindow().getWidth();
		return viewPortWidth < 600;
	}

}
